'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
	//event为客户端上传的参数
	const {articleId,pageSize=10,page=1} = event
	const list=  await db.collection('article').aggregate()
	.match(
	{
		_id:articleId
	}
	).unwind('$comments')
	.project({
		_id:0,
		comments:1
	}).replaceRoot({
		newRoot:'$comments'
	})
	.skip((page-1)*pageSize) // 第一页数据从0开始
	.limit(pageSize) // 每页返回多少条数据
	.end()
	//返回数据给客户端
	return {
		code: 200,
		data: list,
		msg: '评论内容获取成功'
	}
};
